package org.summerframework.component.upload.fastdfs.pool;

import org.summerframework.component.upload.fastdfs.FastDFSTemplateFactory;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.csource.fastdfs.TrackerServer;

/**
 * FastDFS 连接池工厂
 */
public class ConnectionPoolFactory {

    private GenericObjectPool<TrackerServer> pool;

    public ConnectionPoolFactory(FastDFSTemplateFactory fastDFSTemplateFactory) {
        pool = new GenericObjectPool<>(new ConnectionFactory(fastDFSTemplateFactory));
        pool.setConfig(fastDFSTemplateFactory);
    }

    public TrackerServer getServer() throws Exception {
        return pool.borrowObject();
    }

    public void releaseConnection(TrackerServer server) {
        pool.returnObject(server);
    }
}
